# punch_logs/models.py
from django.db import models
from users.models import User

class PunchLog(models.Model):
    # 枚举类型的选择
    PUNCH_TYPE_CHOICES = [
        ('morning', 'Morning'),  # 早打卡
        ('night', 'Night'),  # 晚打卡
    ]

    # 打卡字段
    user = models.ForeignKey(User, on_delete=models.CASCADE, related_name='punch_logs')  # 关联用户
    punch_type = models.CharField(max_length=10, choices=PUNCH_TYPE_CHOICES)  # 打卡类型（早/晚）
    date = models.DateTimeField(auto_now_add=True)  # 打卡日期
    time = models.DateTimeField(auto_now_add=True)  # 打卡时间
    is_makeup = models.BooleanField(default=False)  # 是否补签
    note = models.TextField(null=True, blank=True)  # 备注

    def __str__(self):
        return f"{self.user} - {self.punch_type} - {self.date.strftime('%Y-%m-%d %H:%M:%S')}"
